<template>
	<view class="icons" @click.stop="likeTap">
		<uni-icons :type="like?'heart-filled':'heart'" size="20" color="red"></uni-icons>
	</view>

</template>

<script>
	export default {
		props:{
			item:{
				type:Object,
				default(){
					return {}
				}
			}
		},
		name: "likes",
		data() {
			return {
				like:false
			};
		},
		watch:{
			item(newVal){
				this.like = this.item.is_like
			}
		},
		created() {
			this.like = this.item.is_like
		},
		methods:{
			likeTap(){
				this.like = !this.like
				this.updateLike()
				console.log("点击收藏")
			},
			updateLike(){
				uni.showLoading()
				uni.showToast({
					title:this.like?'收藏成功':'收藏取消',
					icon:'none'
				})
				console.log("like")
				this.$api.update_like({
					user_id:'6053212f73c0390001c4a9eb',
					article_id:this.item._id
				}).then(res=>{
					uni.hideLoading()
				}).catch(()=>{
					uni.hideLoading()
				})
			}
		}
	}
</script>

<style>
	.icons {
		display: flex;
		justify-content: center;
		align-items: center;
		position: absolute;
		width: 20px;
		height: 20px;
		right: 0;
		top: 0;

	}
</style>
